﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.PeerToPeer;

namespace Register
{
    class RegisterProgram
    {
        static void Main(string[] args)
        {

            foreach(Cloud c in Cloud.GetAvailableClouds())
                Console.WriteLine("Name: {0}",c.Name);

            Console.WriteLine("");
            Console.WriteLine("Please enter Peer name classifier:");
            string name = Console.ReadLine();

            PeerName peerName = new PeerName(name,PeerNameType.Unsecured);

            using (PeerNameRegistration reg = new PeerNameRegistration(peerName, 8080))
            {
                string timestamp = string.Format("Created at {0}", DateTime.Now.TimeOfDay);
                reg.Comment = timestamp;

                UnicodeEncoding encoder = new UnicodeEncoding();
                byte[] data = encoder.GetBytes(timestamp);
                reg.Data = data;

                try
                {
                    reg.Start();
                    Console.WriteLine("Peer Registration Successful");
                    Console.WriteLine("peer name host:{0}", reg.PeerName.PeerHostName);

                    Console.WriteLine("Press Enter to Quit");
                    Console.ReadLine();

                    reg.Stop();


                }
                catch (PeerToPeerException ex)
                {
                    Console.WriteLine("peer to Peer Exception Thrown {0}", ex.Message);
                }
            }

        }
    }
}
